package com.songlanyun.modules.rabbitmq.mq.consumer;


import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.rabbitmq.service.MessageHelper;
import com.songlanyun.modules.singlegoods.entity.UnderStockRecordEntity;
import com.songlanyun.modules.singlegoods.service.UnderStockRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 更新库存不足的单品记录状态
 */
@Component
@Slf4j
public class UnderStockStatusConsumer extends BaseConsumer {

    @Resource
    private UnderStockRecordService underStockRecordService;

    @Override
    protected void process(Message message) {
        Long singleGoodsId = ClassConvertUtils.objToLong(new String(message.getBody()));

        //发送消息
        underStockRecordService.inStock(singleGoodsId);

    }

    @RabbitListener(queues = MqConstant.UnderStockStatusConstant.UNDER_STOCK_STATUS_QUEUE)
    public void consume(Message message, Channel channel) throws IOException {
        super.handle(message, channel);
    }
}
